#include <iostream>
#include <cstdio>
using namespace std;
long b, p, k, ans;
long quickMod(long b, long p, long k)
{
    long tmp, tmpp;
    if (p <= 1)
        return b % k;
    else
    {
        if (p % 2 == 0)
        {
            tmp = quickMod(b, p / 2, k);
            return (tmp % k) * (tmp % k) % k;
        }
        else
        {
            tmpp = quickMod(b, (p - 1) / 2, k);
            tmp = quickMod(b, (p + 1) / 2, k);
            return (tmp % k) * (tmpp % k) % k;
        }
    }
}
int main()
{
    scanf("%ld%ld%ld", &b, &p, &k);
    ans = quickMod(b, p, k);
    printf("%ld^%ld mod %ld=%ld", b, p, k, ans);
    return 0;
}